/* ClientApp.java 
* Created on Dec 6, 2012 
*@Author: Mr.Viet 
*@Phone: 01683430426 
*@Email: phamvanvietcdhd@gmail.com
*/ 
package com.session8; 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientApp {
	private Socket client;
	private final String host ="localhost";
	private final int port = 1000;
	public ClientApp() {
	}

	public static void main(String[] args) {
		ClientApp app = new ClientApp();
		app.createClient();
	}
	public void createClient(){
		try {
			this.client = new Socket(host,port);
			this.sendMess("Xin Chao");
			//Tao Lang Nghe
			ClientListener l = new ClientListener(this.client);
			l.start();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void sendMess(String mess){
		try {
			PrintWriter out = new PrintWriter(client.getOutputStream());
			out.println(mess);
			out.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
